import React from 'react';
import { Tools } from 'weaver-mobile';

export default {
    addWindowFunc: () => {
        //下载附件
        window.downloadFile = (id,files,relateId,type,obj) => {
            let options = {
                method: 'POST',
                url: '/api/workrelate/common/viewDocFiled',
                params: {id:id,relateId:relateId,type:type}
            }
            Tools.callApi(options).then((data) => {
                if (data.status) {
                    window.openLink.getWeaverFile("/weaver/weaver.file.FileDownload?fileid=" + files + "&download=1")
                }
              });
        }
        //打开附件
        window.openDoc = (id,relateId,type,obj) =>{
            let options = {
                method: 'POST',
                url: '/api/workrelate/common/viewDocFiled',
                params: {id:id,relateId:relateId,type:type}
            }
            Tools.callApi(options).then((data) => {
                if (data.status) {
                    window.openLink.openDocument(id);
                    //window.open("/spa/document/index.jsp?id=" + id + "#/main/document/detail")
                }
            });
        }
        //打开相应的链接
        window.openAppLink = (obj,id,type,relateId,model) =>{
            if(type==37){//文档
                window.openLink.openDocument(id);
            }else{
                let mirror = {
                    7: "/spa/crm/static4mobile/index.html/#/customerCard/",
                    152: "/spa/workflow/static4mobileform/index.html#/req?requestid=",
                    8: "/spa/prj/static4mobile/index.html#/ProjectDetails/0/",
                    1:'/spa/hrm/static4mobile/index.html#/resourceInfo/',
                    "wrlgoal": "/spa/workrelate/static4mobile/index.html#/goalHome/goalDetail?id=",
                    "wrltask": "/spa/workrelate/static4mobile/index.html#/taskHome/taskDetail/",
                    "wrlplan": "/spa/workrelate/static4mobile/index.html#/planHome/planView/index/detail?"
                };
                window.openLink(mirror[type]+id);
            }
        }
        window.openLink.browserOpenLink.set({
            wrlgoal:function (params, type) {
                window.openLink("/spa/workrelate/static4mobile/index.html#/goalHome/goalDetail?id="+params.id);
            },
            wrltsk:function (params, type) {
                window.openLink("/spa/workrelate/static4mobile/index.html#/taskHome/taskDetail/"+params.id);
            },
        });
    }
};